import {FC} from 'react'
import './Login.scss'
import {Form,Input,Button} from 'antd'
import {ILoginParams} from "@/types/api.ts";
import api from "@/api/index.ts"
import storage from '@/utils/storage.ts'
const Login: FC = () => {
  const onFinish = async(values:ILoginParams) => {
    console.log('onFinish')
    const data = await api.login(values)
    storage.set('token',data);
    window.location.href = '/';
  }
  const onFinishFailed = () => {
    console.log('onFinishFailed')
  }
  return (
      <div className={'Login'}>
        <p className={'login-title'}>系统登录</p>
        <Form
            name="basic"
            labelCol={{ span: 8 }}
            wrapperCol={{ span: 16 }}
            style={{ maxWidth: 600 }}
            initialValues={{ remember: true }}
            onFinish={onFinish}
            onFinishFailed={onFinishFailed}
            autoComplete="off"
        >
          <Form.Item<ILoginParams>
              label="username"
              name="username"
              rules={[{ required: true, message: 'Please input your username!' }]}
          >
            <Input />
          </Form.Item>

          <Form.Item<ILoginParams>
              label="userPwd"
              name="userPwd"
              rules={[{ required: true, message: 'Please input your password!' }]}
          >
            <Input.Password />
          </Form.Item>


          <Form.Item label={null}>
            <Button type="primary" htmlType="submit">
              提交
            </Button>
          </Form.Item>
        </Form>
      </div>
  )
}
export default Login
